/**********************************************************
Filename: i2c-net.cpp
Author: Dave Frank (dnfrank@gmail.com)

**********************************************************/
#include <iostream>
#include <i2cNet.h>


i2cNet::i2cNet(const std::string& name)
m_name(name),
m_fd(-1)
{
}

i2cNet::~i2cNet()
{
	if(isOpen())
	{
		close();
	}
}

i2cNet::Status i2cNet::open()
{
    i2cNet::Status retval=FAILURE;
    if(!isOpen())
    {
        m_fd=open(name.c_str(),O_RDWR);
        if(m_fd!=-1)
        {
            retval=SUCCESS;
        }
    }
    else
    {
        retval=SUCCESS;
    }
    return retval;
}

i2cNet::Status i2cNet::close()
{
    i2cNet::Status retval=SUCCESS;
    if(isOpen())
    {
        ::close(m_fd);
        m_fd=-1;
    }
    else
    {
        retval=NOT_OPEN;
    }
}

i2cNet::Status i2cNet::addDevice(i2cDevice& device)
{
    i2cNet::Status retval=FAILURE;
    if(map.find(i2cDevice.name()!=map::end)
    {
        m_devices.insert(i2cDevice.name(),i2cDevice);
    }
    return retval;
}
